using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace XLib
{
    public static class CryptoSettings
    {
        public static readonly bool Enable = true;
        public static readonly string CryptoKey = "xframework";
        private static readonly byte[] encryptbytes = Encoding.UTF8.GetBytes(CryptoKey);

        public static void Encrypt(string path)
        {
            byte[] bytes;
            using (FileStream fileStream = File.OpenRead(path))
            {
                using(var mem = new MemoryStream())
                {
                    fileStream.CopyTo(mem);
                    bytes = mem.ToArray();
                    for(int i=0; i<bytes.Length; i++)
                    {
                        bytes[i] = (byte)(bytes[i] ^ encryptbytes[i % CryptoKey.Length]);
                    }
                }
            }
            File.WriteAllBytes(path, bytes);
        }

        public static byte Decrypt(byte data, long position)
        {
            data = (byte)(data ^ encryptbytes[position % CryptoKey.Length]);
            return data;
        }
    }
}